using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tKitchen
{
    public partial class IngredientInput : Form
    {
        IngredientPresenter presenter;

        public IngredientInput(IngredientPresenter presenterIn)
        {
            InitializeComponent();
            presenter = presenterIn;

        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            List<Ingredient> list = (List<Ingredient>)dataGridView1.DataSource;
            Ingredient temp = list[e.RowIndex];
            presenter.UpdateIngredient(temp);
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            //check for empty boxes first
            //any of them could be null, but make sure then put somehting in
            if (textBoxDescr.Text != "" || textBoxName.Text != "")
            {

                presenter.AddIngredient(textBoxName.Text, textBoxDescr.Text);
                textBoxName.Clear();
                textBoxDescr.Clear();
                textBoxName.Focus();
            }
        }

        public void SetDataSource(List<Ingredient> list)
        {
            dataGridView1.DataSource = list;
        }


        internal void RefreshGrid()
        {
            dataGridView1.Refresh();
        }

    }
}